package org.example.api;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

/**
 * {@code @BelongsProject:}xkLab
 * {@code @BelongsPackage:}org.example.api
 * {@code @Author:} Xukai
 * {@code @CreateTime:}2025-04-22  10:48
 * {@code @Description:
 * 前置条件:httpclient(pom.xml)
 * 需要手动调整apiKey和ModelID}
 * {@code @Version:}1.0
 */
public class map {
    public static void main(String[]args) throws Exception {
        testGet();
    }
    public static void testGet() throws Exception{
        //创建HttpClient
        CloseableHttpClient httpClient = HttpClients.createDefault();
        //创建get对象
        HttpGet httpGet = new HttpGet("https://restapi.amap.com/v3/weather/weatherInfo?city=your_city&key=your_api_key");   //需要手动调整
        //发送请求(将前两项封装)
        CloseableHttpResponse response = httpClient.execute(httpGet);

        //解析状态码与信息:
        int statusCode = response.getStatusLine().getStatusCode();
        System.out.println("返回状态码:" + statusCode);
        HttpEntity httpEntity = response.getEntity();
        String body = EntityUtils.toString(httpEntity);
        System.out.println("返回信息:" + body);

        //关闭资源
        response.close();
        httpClient.close();
    }
}
